package pers.whj.net.local.exception;

public enum ErrorCodeEnum implements ErrorCode {
    UNSPECIFIED(101, "未知错误"),
    NOT_FIND_SERVER(201, "未找到服务器"),
    DISCONNECTION(202, "网络连接未建立"),
    FAIL_INIT_CLIENT_NAME(203, "服务端初始化客户端名失败"),
    EMPTY_CLIENT_NAME(204, "客户端名不能为空"),
    REMOTE_FILE_NOT_EXIST(301, "服务端不存在此文件"),
    REMOTE_EMPTY_FILE_NAME(302, "指定服务端文件路径为空"),
    REMOTE_FAIL_MAKE_DIRECTORY(303, "服务端创建文件夹失败"),
    REMOTE_FAIL_MAKE_FILE(304, "服务端创建文件失败"),
    REMOTE_FILE_IS_DIRECTORY(305, "指定服务端路径为文件夹"),
    REMOTE_FILE_IS_NOT_DIRECTORY(306, "指定服务端文件不是文件夹"),
    REMOTE_FAIL_WRITE_FILE(307, "服务端写文件出错"),
    REMOTE_FAIL_DELETE_FILE(308, "删除服务端文件失败"),
    REMOTE_FAIL_RENAME_FILE(309, "重命名服务端文件失败"),
    REMOTE_FILE_NAME_EXIST(310, "服务端存在同名的文件"),
    FILE_DIRECTORY(401, "不能直接上传或下载文件夹"),
    FILE_NOT_EXIST(402, "文件不存在"),
    FILE_NOT_DIRECTORY(403, "指定文件不是文件夹"),
    UPLOAD_DIRECTORY_OVER_LIMIT(404, "上传文件夹中文件数量超过限制");

    private final int code;
    private final String description;

    ErrorCodeEnum(final int code, final String description) {
        this.code = code;
        this.description = description;
    }

    public static ErrorCodeEnum getByCode(int code) {
        for (ErrorCodeEnum value : ErrorCodeEnum.values()) {
            if (value.getCode() == code) {
                return value;
            }
        }
        return UNSPECIFIED;
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }
}